#include "contentarea.h"

ContentArea::ContentArea(QWidget *parent) : QWidget(parent)
{

}

void ContentArea::setpermission(QString permission)
{
    this->permission=permission;

    //setWindowIcon(QIcon(":/icon/farm2.png"));
    QVBoxLayout *layout = new QVBoxLayout(this);
        layout->setContentsMargins(0, 0, 0, 0); // 无外边距

        // 创建堆叠窗口
        stackedWidget = new QStackedWidget(this);
        layout->addWidget(stackedWidget);

        // 创建各个功能页面
        farmManagementWidget = new FarmManagementWidget();
        collaborationWidget = new CollaborationWidget();
        farmInfoWidget = new FarmInfoWidget(this,permission);

        // 添加到堆叠窗口
        stackedWidget->addWidget(farmManagementWidget);
        stackedWidget->addWidget(collaborationWidget);
        stackedWidget->addWidget(farmInfoWidget);

        // 默认显示农场管理页面
        showFarmManagement();
        connect(farmManagementWidget, &FarmManagementWidget::farmSelected,
                farmInfoWidget, &FarmInfoWidget::setFarmId);


}

void ContentArea::showFarmManagement()
{
    stackedWidget->setCurrentWidget(farmManagementWidget);
}

void ContentArea::showCollaboration()
{
    stackedWidget->setCurrentWidget(collaborationWidget);
}

void ContentArea::showFarmInfo()
{
    stackedWidget->setCurrentWidget(farmInfoWidget);
}

